import { _decorator, Component, Node, sp, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('AnimatorComp')
export class AnimatorComp extends Component {
    private _spine : sp.Skeleton;

    protected onLoad(): void {
        this._spine = this.node.getComponent(sp.Skeleton);
        this._spine.setCompleteListener(this.onAnimationComplete.bind(this));
    }

    public play(animaName: string, speed: number = 1, loop: boolean = false): void {
        // TODO: implement
        this._spine.timeScale = speed;
        this._spine.setAnimation(0, animaName, loop);
    }

    onAnimationComplete(trackEntry: any): void {
        console.log('onAnimationComplete', trackEntry.animation.name);
        
    }

}